package cn.shanke.torrentmanagerserver.controller;

import cn.shanke.torrentmanagerserver.controller.common.ResponseModel;
import cn.shanke.torrentmanagerserver.model.Library;
import cn.shanke.torrentmanagerserver.service.LibraryService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/library")
public class LibraryController {
    @Resource
    private LibraryService modelService;

    @GetMapping("/list")
    public ResponseModel listModels() {
        return ResponseModel.success().data(modelService.list(null));
    }

    @GetMapping(value = "/find/{id}")
    public ResponseModel getModelById(@PathVariable("id")Long id) {
        return ResponseModel.success().data(modelService.getById(id));
    }

    @PostMapping("/save")
    public ResponseModel saveModel(@RequestBody Library model) {
        modelService.saveOrUpdate(model);
        return ResponseModel.success().data(model.getId());
    }

    @GetMapping("/delete/{id}")
    public ResponseModel deleteModel(@PathVariable("id")Long id) {
        modelService.removeById(id);
        return ResponseModel.success();
    }

    @GetMapping("/options")
    public ResponseModel options() {
        return ResponseModel.success().data(modelService.list(null));
    }
}
